package br.com.clinica.supercao.service.impl;

import br.com.clinica.supercao.dao.ConsultaDAO;
import br.com.clinica.supercao.dao.impl.ConsultaDAOImpl;
import br.com.clinica.supercao.entity.Consulta;
import br.com.clinica.supercao.entity.filter.AnimalSearchFilter;
import br.com.clinica.supercao.entity.filter.ConsultaSearchFilter;
import br.com.clinica.supercao.service.AnimalService;
import br.com.clinica.supercao.service.ConsultaService;
import br.com.rpteixeira.exceptions.ServiceExcetion;
import br.com.rpteixeira.service.AbstractEntityService;

public class ConsultaServiceImpl extends
		AbstractEntityService<Consulta, ConsultaSearchFilter, ConsultaDAO> implements
		ConsultaService {
	
	@Override
	protected void doPreInsert(Consulta entity) throws ServiceExcetion {
		entity.setAnimal(getAnimalService().find( getFiltroComNome(entity.getAnimal().getNome())).get(0));
		entity.getAnimal().getConsultas().add(entity);
	}
	@Override
	public ConsultaDAO getEntityDAO() {
		return new ConsultaDAOImpl();
	}
	private AnimalService getAnimalService(){
		return new AnimalServiceImpl();
	}
	private AnimalSearchFilter getFiltroComNome(String nome){
		AnimalSearchFilter animal= new AnimalSearchFilter();
		animal.setNome(nome);
		return animal;
	}
}
